package fun._6742.controller;

import fun._6742.utils.oss.MinioTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "资源")
@RestController
@RequestMapping("/api/resource/v1")
public class ResourceController {


    @Resource
    MinioTemplate minioTemplate;

    @ApiOperation(value = "上传资源")
    @PostMapping("/")
    public String uploadResource(@ApiParam @RequestPart("file") MultipartFile file) {
        if (file.isEmpty()) {
            return "上传失败，请选择文件";
        }
        return minioTemplate.putObject(file).getOssFilePath();
    }
}
